import {
	defineStore
} from 'pinia'

export const app = defineStore('APP', {
	persist: true,
	state: () => ({
		tasks: JSON.parse(uni.getStorageSync('tasks') || '[]')
	}),
	actions: {
		// 创建关系
		addTask(obj) {
			this.tasks.push(obj)
			uni.setStorageSync('tasks', JSON.stringify(this.tasks))

			uni.showToast({
				title: '创建成功'
			})
		},
		// 删除关系
		delTask(index) {
			this.tasks.splice(index, 1)
			uni.setStorageSync('tasks', JSON.stringify(this.tasks))
		}
	},

	getters: {
		getTasks: (state) => state.tasks
	}
})
